package com.wc.codeforces.前缀和与差分.前缀和.The_Endspeaker_Hard_Version;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/27 0:25
 * @description https://codeforces.com/contest/2027/problem/D2
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010, INF = 0x3f3f3f3f;
    static int[] a = new int[N], b = new int[N];
    static int[] rmax = new int[N];
    static long[] s = new long[N];
    static int[][] f, g;
    static int n, m, mod = (int) 1e9 + 7;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            int maxv = 0;
            for (int i = 1; i <= n; i++) {
                a[i] = sc.nextInt();
                maxv = Math.max(maxv, a[i]);
            }
            for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
            for (int i = 1; i <= m; i++) b[i] = sc.nextInt();
            if (maxv > b[1]) out.println(-1);
            else {
                rmax[n + 1] = 0;
                for (int i = n; i >= 1; i--) rmax[i] = Math.max(a[i], rmax[i + 1]);
                // f[i][j] 表示从a -> i 走到 k -> j 的所花的钱
                f = new int[n + 1][m + 1];
                g = new int[n + 1][m + 1];
                for (int i = 1; i <= n; i++) Arrays.fill(f[i], INF);
                for (int i = 1; i <= m; i++) f[0][i] = 0;
                for (int j = 1; j <= m; j++) {
                    for (int i = 1; i <= n; i++) {
                        f[i][j] = f[i][j - 1];
                        g[i][j] = g[i][j - 1];
                    }
                    for (int i = 1; i <= n; i++) {
                        int l = 0, r = i - 1;
                        while (l < r) {
                            int mid = l + r >> 1;
                            if (s[i] - s[mid] <= b[j]) r = mid;
                            else l = mid + 1;
                        }
                        if (s[i] - s[r] <= b[j]) f[i][j] = Math.min(f[i][j], f[r][j] + m - j);
                    }
                }
                int res = INF;
                for (int i = 1; i <= m; i++) res = Math.min(f[n][i], res);
                out.println(res);
            }
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
